package com.admin.thread;

import java.util.List;
import java.util.concurrent.BlockingQueue;

import org.apache.log4j.Logger;

import com.admin.bean.TempOrderBean;
import com.admin.dao.TempOrderDao;

public class GetTempOrderThread implements Runnable {

	private static final Logger log = Logger.getLogger(GetTempOrderThread.class);
	private TempOrderDao tempOrderDao;

	private BlockingQueue<TempOrderBean> dataQueue;

	public GetTempOrderThread(BlockingQueue<TempOrderBean> dataQueue, TempOrderDao tempOrderDao) {
		this.dataQueue = dataQueue;
		this.tempOrderDao = tempOrderDao;
	}

	@Override
	public void run() {
//		while (!Thread.interrupted()) {
//			if (dataQueue.size() == 0) {// 如果队列大小小于10，则进行生产
//				List<TempOrderBean> tempOrderList = tempOrderDao.findTempOrder(0, 10 - dataQueue.size());
//				if (tempOrderList == null || tempOrderList.size() == 0) {// 如果数据库没有，则线程休眠
//					log.info("数据库没有订单,获取订单线程休眠5分钟===>");
//				} else {
//				    try {
//						for (TempOrderBean tempOrderBean : tempOrderList) {
//							log.info(Thread.currentThread().getName()+"：加入队列==>"+tempOrderBean.getTempId());
//                            dataQueue.put(tempOrderBean);
//						}
//				    } catch (InterruptedException e) {
//				        e.printStackTrace();
//				    }
//				}
//			} else {// 队列不为空，线程休眠
//				log.info("队列不为空,获取订单线程休眠5分钟===>");
//			}
//			try {
//                Thread.sleep(5 * 60 * 1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//		}
	}
}
